package algorithms;

import org.junit.Test;

import java.util.*;

public class BitMap extends Binomial{
    private byte[] byteBits;

    private int maxValue;

    private int capacity;
//    public BitMap(){
//
//    }
    public BitMap(int maxValue) {
   //     this();
   //     this.www();
        this.maxValue = maxValue;
        this.capacity = (maxValue / 8) + 1;
        byteBits = new byte[capacity];
    }


    public void add (int num) {
      //  this.www();
        int index = num / 8;
        int position = num % 8;
        int tempBit = 1<<position; //这个是核心，存储的结构bitmap
        byteBits[index] = (byte) (byteBits[index] | tempBit);
    }

    public boolean contains(int num) {

        int index = num / 8;
        int position = num % 8;
        int temoBit = 1<<position;
        return (byteBits[index] & temoBit) !=0;

    }

    static class ww{

        public static void main(String[] args) {
            System.err.println('a' - 0);
//            String osName = System.getProperty("os.name");
//            System.err.println(osName);
//            BitMap b = new BitMap(10);
//            b.add(10);
//            b.contains(10);
        }
    }
}
